<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>append()</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="index.html" title="Smarty 3 Manual">
<link rel="up" href="api.functions.html" title="Chapter 14. Smarty Class Methods">
<link rel="prev" href="api.add.template.dir.html" title="addTemplateDir()">
<link rel="next" href="api.append.by.ref.html" title="appendByRef()">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">append()</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="api.add.template.dir.html">Prev</a> </td>
<th width="60%" align="center">Chapter 14. Smarty Class Methods</th>
<td width="20%" align="right"> <a accesskey="n" href="api.append.by.ref.html">Next</a>
</td>
</tr>
</table>
<hr>
</div>
<div class="refentry" title="append()">
<a name="api.append"></a><div class="titlepage"></div>
<div class="refnamediv">
<h2>Name</h2>
<p>append() — append an element to an assigned array</p>
</div>
<div class="refsect1" title="Description">
<a name="id426416"></a><h2>Description</h2>
<code class="methodsynopsis"><span class="type">void </span><span class="methodname">append</span>(<span class="methodparam"><span class="type">mixed </span><span class="parameter">var</span></span>);</code><br><code class="methodsynopsis"><span class="type">void </span><span class="methodname">append</span>(<span class="methodparam"><span class="type">string </span><span class="parameter">varname</span></span>,<br>            <span class="methodparam"><span class="type">mixed </span><span class="parameter">var</span></span>,<br>            <span class="methodparam"><span class="type">bool </span><span class="parameter">merge</span></span>);</code><p>
If you append
   to a string value, it is converted to an array value and then
   appended to. You can explicitly pass name/value pairs, or associative
   arrays containing the name/value pairs. If you pass the optional third
   parameter of <code class="constant">TRUE</code>, the value will be merged with the current array
   instead of appended.
  </p>
<div class="note" title="Technical Note" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Technical Note</h3>
<p>
  The <em class="parameter"><code>merge</code></em> parameter respects array keys, so if
  you merge two numerically indexed arrays, they may overwrite each other
  or result in non-sequential keys. This is unlike the PHP
  <a class="ulink" href="http://php.net/array_merge" target="_top">
  <code class="varname">array_merge()</code></a> function
   which wipes out numerical keys and renumbers them.
 </p>
</div>
<div class="example">
<a name="id426997"></a><p class="title"><b>Example 14.4. append</b></p>
<div class="example-contents"><pre class="programlisting">

&lt;?php
// This is effectively the same as assign()
$smarty-&gt;append('foo', 'Fred');
// After this line, foo will now be seen as an array in the template
$smarty-&gt;append('foo', 'Albert');

$array = array(1 =&gt; 'one', 2 =&gt; 'two');
$smarty-&gt;append('X', $array);
$array2 = array(3 =&gt; 'three', 4 =&gt; 'four');
// The following line will add a second element to the X array
$smarty-&gt;append('X', $array2);

// passing an associative array
$smarty-&gt;append(array('city' =&gt; 'Lincoln', 'state' =&gt; 'Nebraska'));
?&gt;

   </pre></div>
</div>
<br class="example-break"><p>See also
  <a class="link" href="api.append.by.ref.html" title="appendByRef()"><code class="varname">appendByRef()</code></a>,
  <a class="link" href="api.assign.html" title="assign()"><code class="varname">assign()</code></a>
  and
  <a class="link" href="api.get.template.vars.html" title="getTemplateVars()"><code class="varname">getTemplateVars()</code></a>
  </p>
</div>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="api.add.template.dir.html">Prev</a> </td>
<td width="20%" align="center"><a accesskey="u" href="api.functions.html">Up</a></td>
<td width="40%" align="right"> <a accesskey="n" href="api.append.by.ref.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">addTemplateDir() </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top"> appendByRef()</td>
</tr>
</table>
</div>
</body>
</html>
